#include "detailwidget.h"
#include "ui_detailwidget.h"
#include <QDebug>
#include <QMessageBox>
#include "database.h"

DetailWidget::DetailWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DetailWidget)
{
    ui->setupUi(this);

    this->setWindowTitle("商品详情");
    this->setWindowIcon(QIcon(":/sources/image/详情.png"));
}

DetailWidget::~DetailWidget()
{
    delete ui;
}

///设置详情页信息
/// 功能：初始化详情页
void DetailWidget::SetDetilsWidget(QVector<QString> PhoneDetilsInfo)
{

    QString PictureName = "../Phone_platform/sources/picture" + PhoneDetilsInfo.at(9);
//        qDebug() << PhoneDetilsInfo;
//        qDebug() << PictureName;
    ui->lb_ModelNumber->setText(PhoneDetilsInfo.at(0));
    ui->lb_Price->setText(PhoneDetilsInfo.at(1));
    ui->lb_ScreenSize->setText(PhoneDetilsInfo.at(2));
    ui->lb_ScreenreSolution->setText(PhoneDetilsInfo.at(3));
    ui->lb_Ram->setText(PhoneDetilsInfo.at(4));
    ui->lb_Rom->setText(PhoneDetilsInfo.at(5));
    ui->lb_CPU->setText(PhoneDetilsInfo.at(6));
    ui->lb_Battery->setText(PhoneDetilsInfo.at(7));
    ui->lb_CameraPixels->setText(PhoneDetilsInfo.at(8));

//    QImage img(PictureName);
//    qDebug() << PictureName + "001.jpg";
    ui->lb_PhonePicture1->setPixmap(QPixmap::fromImage(QImage(PictureName + "001.jpg")));
    ui->lb_PhonePicture2->setPixmap(QPixmap::fromImage(QImage(PictureName + "002.jpg")));
    ui->lb_PhonePicture3->setPixmap(QPixmap::fromImage(QImage(PictureName + "003.jpg")));
    ui->lb_PhonePicture4->setPixmap(QPixmap::fromImage(QImage(PictureName + "004.jpg")));
}

//加入购物车
void DetailWidget::on_pb_JoinShoppingCar_clicked()
{
    emit JoinShoppingCar(ui->lb_ModelNumber->text());
}


///添加购物车提示消息
///在详情界面上显示消息提示框
void DetailWidget::JoinShowHintWidget(QString Flag)
{
    qDebug() << "DetailWidget::JoinShowHintWidget" << Flag.toInt();
    switch (Flag.toInt())
    {
        //成功
        case 0:
        {
            QMessageBox msgBox;
            msgBox.setWindowTitle(" ");
            msgBox.setText("添加成功！");
            msgBox.setWindowIcon(QIcon(":/sources/image/成功.png"));
            msgBox.exec();
            break;
        }

        //已存在
        case 1:
        {
            QMessageBox::warning(this, tr("提示："),tr("已存在购物车中！"));
            break;
        }
    }
}

///购买提示消息
///在详情界面上显示消息提示框
void DetailWidget::BuyShowHintWidget(char Flag)
{
    switch (Flag)
    {
        //成功
        case 0:
        {
            QMessageBox msgBox;
            msgBox.setWindowTitle(" ");
            msgBox.setText("下单成功！");
            msgBox.setWindowIcon(QIcon(":/sources/image/成功.png"));
            msgBox.exec();
            break;
        }

        //已存在
        case -1:
        {
            QMessageBox::warning(this, tr("提示："),tr("下单失败！"));
            break;
        }
    }
}


///购买函数
/// 功能：出购物车，进订单列表
void DetailWidget::on_pushButton_2_clicked()
{
    emit SignalBuyNow(ui->lb_ModelNumber->text(),ui->lb_Price->text());
}


//// 联系客服按钮
void DetailWidget::on_pb_CustomerService_clicked()
{






}
